#include "base/count_down_cond.h"
namespace net_tools{
Count_down_cond::Count_down_cond(int val)
  :mutex_(),
   cond_(mutex_),
   count_(val)
{
};
void Count_down_cond::Wait(){
  mutex_.Lock();
  while(count_ != 0){
    cond_.Wait();
  }
  mutex_.Unlock();
};
void Count_down_cond::Signal(){
  mutex_.Lock();
  --count_;
  if(count_ == 0){
    cond_.Signal_all();
  }
  mutex_.Unlock();
};
void Count_down_cond::Set_count(int count){
  count_ = count;
};
void Count_down_cond::Add_count(int count){
  count_ += count;
};

} // namespace net_tools